<template>
	<!-- 推送设置 -->
	<view>
		<view class="flex-bc moreItem" v-for="(item,index) in pushList" :key="index">
			<text>{{item.name}}</text>
			<image src="../../../static/user/push-open.png" v-if="item.status" @click="fnChangeStatus(item.status,item.type,index)"></image>
			<image src="../../../static/user/push-close.png" v-else @click="fnChangeStatus(item.status,item.type,index)"></image>
		</view>
		<view class="warming">
			<view class="title">
				温馨提示
			</view>
			<view class="content" v-html="content">
				
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				token:uni.getStorageSync('token'),
				pushList:[],
				content:[]
			};
		},
		onShow() {
			this.fnGetPushData()
		},
		methods:{
			fnGetPushData(){
				this.request({
					url: '/czb/User/getPushStatusList',
					method: 'POST',
					data: {
						'store_id': 1,
						'token':this.token
					},
				}).then((ret) => {
					console.log(ret);
					if (ret.code == 0) {
						this.pushList = ret.data.config
						this.content = ret.data.content
						console.log(this.content)
					}
				})
			},
			fnChangeStatus(status,type,idx){
				this.pushList.forEach((item,index)=>{
					if(index == idx){
						item.status = !item.status
						console.log(this.pushList)
						this.request({
							url: '/czb/User/updatePushStatus',
							method: 'POST',
							data: {
								'store_id': 1,
								'type':type,
								'token':this.token
							},
						}).then((ret) => {
							console.log(ret);
							if (ret.code == 0) {
								uni.showToast({
									title:ret.message,
									icon:'success'
								})
							}
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.moreItem {
		height: 100rpx;
		padding: 0 20rpx;
		font-size: 30rpx;
		background: #fff;
		border-bottom: 1rpx solid #e3e3e3;
		image{
			width: 100rpx;
			height: 60rpx;
		}
	}
	.warming{
		padding: 0 20rpx;
		font-size: 28rpx;
		margin-top: 40rpx;
		.title{
			margin-bottom: 20rpx;
		}
		.content{
			font-size: 26rpx;
			color: #666;
		}
	}
</style>
